var /**
	 * 仿真流程管理
	 */
TeachFlow = cc.Class.extend({
	step:0,
	flow:null,
	main:null,
	over_flag: false,
	curSprite:null,
	ctor: function(){
		this.init();
	},
	setMain:function(main){
		this.main=main;
	},
	init: function(){
		for(var i in teach_flow){
			teach_flow[i].finish = false;
			teach_flow[i].cur = false;
			if(teach_flow[i].action == null){
				teach_flow[i].action = ACTION_NONE;				
			}
			if(teach_flow[i].lock == null){
				teach_flow[i].lock = true;
			}
		}
	},
	start:/**
			 * 开始流程
			 */
	function(){
		this.over_flag = false;
		this.step = 0;
		
		/* 新标准，开始的时候，执行下一步 */
		this.next();
	},
	over:/**
			 * 流程结束，计算分数，跳转到结束场景，
			 */
	function(){
		this.over_flag = true;
		this.flow = over;
		gg.lastStep = this.step;
		this.main.over();
	},
	checkTag:/**
				 * 检查是否当前步骤
				 * 
				 * @deprecated 使用新Angel类，不再判断是否当前步骤
				 * @param tag
				 * @returns {Boolean}
				 */
	function(tag){
		var cur_flow = teach_flow[this.step - 1];
		if(cur_flow.tag == tag){
			return true;
		} else {
			return false;
		}
	},
	prev:/**
			 * 回退一定步数
			 * 
			 * @deprecated 需结合具体实现，，暂时不再启动
			 * @param count
			 *            步数
			 */
	function(count){
		if(this.curSprite!=null){
// this.curSprite.stop();
			this.curSprite = null;
		}
		if(this.flow!=null){
			this.flow.cur = false;
		}
		this.step = this.step - count;
		this.flow = teach_flow[this.step - 1];
		this.refresh();
		gg.score -= 11;
	},
	next:/**
			 * 执行下一步操作， 定位当前任务
			 */
	function(){
		if(this.over_flag){
			return;
		}
		if(this.curSprite!=null){
			this.curSprite.setEnable(false)
			this.curSprite = null;
		}
		if(this.flow!=null){
			this.flow.cur = false;
			// 标记任务已完成
			this.flow.finish = true;
		}
		this.flow = teach_flow[this.step++];
		if(this.flow.finish){
			// 如果任务已完成，跳过当前步骤
			this.next();
		}
		this.refresh();
	},
	refresh:/**
			 * 刷新当前任务状态，设置闪现，点击等状态
			 */
	function(){
		// 刷新提示
		this.flow.cur = true;
		if(this.flow.tip != null){
			ll.tip.tip.doTip(this.flow.tip);
		}
		if(this.flow.flash != null){
			ll.tip.flash.doFlash(this.flow.flash);
		}
		if(this.step > teach_flow.length - 1){
			this.over();
		}
		this.initCurSprite();
		if(this.curSprite!=null){
			this.location();
			this.curSprite.setEnable(true);
		}		
		var before = teach_flow[this.step - 2];
		if(before == null || before.lock){
			gg.synch_listener = true;	
		}
	},
	location:/**
				 * 定位箭头
				 */
	function(){
		var tag = gg.flow.flow.tag;
		if(tag instanceof Array){
			if(TAG_LIB_MIN < tag[1]){
				if(ll.run.lib.isOpen()){
					ll.tip.arr.pos(this.curSprite);
				}else{
					ll.tip.arr.setPosition(gg.width-45,455);
				}
			}else{
				ll.tip.arr.pos(this.curSprite);
			}
		}
			else {
				ll.tip.arr.pos(this.curSprite);
		}		
	},
	getStep:/**
			 * 获取当前步数
			 * 
			 * @returns {Number}
			 */
	function(){
		return this.step;
	},
	initCurSprite:/**
					 * 遍历获取当前任务的操作对象
					 */
	function(){
		var tag = this.flow.tag;
		if(tag == null || tag == undefined){
			return;
		}
		var root = ll.run;
		var sprite = null;
		if(tag == TAG_BUTTON_LIB){
			sprite = ll.tool.getChildByTag(tag);
		} else if(tag instanceof Array){
			// 数组
			for (var i in tag) {
				root = root.getChildByTag(tag[i]);
			}
			sprite = root;
		} else {
			// 单个tag
			var sprite = root.getChildByTag(tag);
		}
		if(sprite != null){
			this.curSprite = sprite;			
			return;
		}
		
	}
});

// 任务流
teach_flow = [

	{tip:"打开药品库",tag:TAG_BUTTON_LIB},
	{tip:"取出托盘天平",tag:[TAG_LIB,TAG_LIB_TIANPING]},
	{tip:"取出两张称量纸",tag:[TAG_LIB,TAG_LIB_CHENGLIANGZHI]},
	{tip:"取出砝码盒",tag:[TAG_LIB,TAG_LIB_FAMAHE]},
	{tip:"将称量纸分别放置天平左右托盘",tag:[TAG_CHENGLIANGZHI]},
	{tip:"调整平衡螺母，至天平平衡",tag:[TAG_TIANPING,TAG_LUOMU]},
	{tip:"打开砝码盒",tag:[TAG_FAMAHE]},
	{tip:"取出5克砝码放置天平右托盘",tag:[TAG_FAMA]},
	{tip:"取出粗苯甲酸样品瓶",tag:[TAG_LIB,TAG_LIB_CUBENJIASUAN]},
	{tip:"打开瓶塞",tag:[TAG_CUBENJIASUAN_BOTTLE,TAG_PINGSAI]},
	{tip:"用药匙，取5g粗苯甲酸,放在天平左托盘",tag:[TAG_CUBENJIASUAN_BOTTLE,TAG_GANGSHAO]},	

	{tip:"在药品库中取出一个烧杯1号",tag:[TAG_LIB,TAG_LIB_BEAKER],action:ACTION_DO1},
	{tip:"把粗苯甲酸放入烧杯1号",tag:TAG_CHENGLIANGZHI1},
	{tip:"在药品库中取出量筒",tag:[TAG_LIB,TAG_LIB_CYLINDER]},
	{tip:"在药品库中取出蒸馏水",tag:[TAG_LIB,TAG_LIB_KETTLE],action:ACTION_DO1},
	{tip:"量筒量取50毫升蒸馏水",tag:[TAG_KETTLE,TAG_KETTLE1]},
	{tip:"将量取的蒸馏水加入1号烧杯中",tag:TAG_CYLINDER},
	
	{tip:"在药品库中取出三脚架",tag:[TAG_LIB,TAG_LIB_SANJIAOJIA]},
	{tip:"在药品库中取出石棉网，放置三脚架上",tag:[TAG_LIB,TAG_LIB_SHIMIANWANG]},
	{tip:"将1号烧杯转移到三脚架上",tag:[TAG_BEAKER],action:ACTION_DO1},
	{tip:"在药品库中取出酒精灯和火柴",tag:[TAG_LIB,TAG_LIB_JIUJINGDENG]},
	{tip:"打开酒精灯灯帽",tag:[TAG_LAMP,TAG_DENGMAO],action:ACTION_DO1},
	{tip:"用火柴点燃酒精灯",tag:[TAG_LAMP,TAG_HUOCHAI]},
	{tip:"将酒精灯移至三脚架下",tag:[TAG_LAMP,TAG_JIUJINGDENG],action:ACTION_DO3},
	{tip:"在药品库中取出玻璃棒，边加热，边搅拌",tag:[TAG_LIB,TAG_LIB_BOLIBANG],action:ACTION_DO1},
	{tip:"等待粗苯甲酸全部溶解"},	
	{tip:"将1号烧杯移出三脚架上",tag:[TAG_BEAKER],action:ACTION_DO2},		
	{tip:"在药品库中取出活性炭",tag:[TAG_LIB,TAG_LIB_HUOXINGTAN]},
	{tip:"打开瓶塞",tag:[TAG_HUOXINGTAN_BOTTLE,TAG_PINGSAI]},
	{tip:"用药匙，取适量活性炭至烧杯",tag:[TAG_HUOXINGTAN_BOTTLE,TAG_GANGSHAO]},
	{tip:"将1号烧杯重新移到三脚架上",tag:[TAG_BEAKER],action:ACTION_DO1},
	{tip:"在药品库中取出玻璃棒，边加热，边搅拌",tag:[TAG_LIB,TAG_LIB_BOLIBANG],action:ACTION_DO2},
	{tip:"加热3-5分钟,至沸腾"},
	
	{tip:"在药品库中取出铁架台",tag:[TAG_LIB,TAG_LIB_TIEJIATAI]},
	{tip:"在药品库中取出热滤漏斗",tag:[TAG_LIB,TAG_LIB_RELVLOUDOU]},	
	{tip:"药品库中取出蒸馏水",tag:[TAG_LIB,TAG_LIB_KETTLE],action:ACTION_DO2},
	{tip:"向热滤漏斗注水口注水",tag:[TAG_KETTLE,TAG_KETTLE2]},
	{tip:"将注水后的热率漏斗放置铁架台",tag:[TAG_RELVLOUDOU]},
	{tip:"在药品库中取出滤纸，将滤纸按需要折叠",tag:[TAG_LIB,TAG_LIB_LVZHI]},
	{tip:"读完折叠说明，点击右上角，关闭窗口",tag:[TAG_WIN_NODE,TAG_LVZHI_CLOSE],action:ACTION_DO1},
	{tip:"滤纸放置热滤漏斗中",tag:[TAG_LVZHI],action:ACTION_DO1},
	{tip:"在药品库中取出烧杯2号放在铁架上",tag:[TAG_LIB,TAG_LIB_BEAKER],action:ACTION_DO2},
	{tip:"将酒精灯移至热滤漏斗下持续加热",tag:[TAG_LAMP,TAG_JIUJINGDENG],action:ACTION_DO1},
	{tip:"在药品库中取出玻璃棒",tag:[TAG_LIB,TAG_LIB_BOLIBANG]},
	{tip:"读完摆放说明，关闭窗口，继续实验",tag:[TAG_WIN_NODE,TAG_LVZHI_CLOSE]},
	{tip:"把烧杯1号中的粗盐溶液通过引流过滤，弃去杂质",tag:TAG_BEAKER,action:ACTION_DO3},	
	{tip:"将酒精灯移出铁架台",tag:[TAG_LAMP,TAG_JIUJINGDENG],action:ACTION_DO2},
	{tip:"灯帽熄灭",tag:[TAG_LAMP,TAG_DENGMAO],action:ACTION_DO2},
	{tip:"拿起灯帽，重新盖一次",tag:[TAG_LAMP,TAG_DENGMAO],action:ACTION_DO3},	
	{tip:"等待结晶"},
	
	{tip:"在药品库中取出减压抽滤装置",tag:[TAG_LIB,TAG_LIB_CHOULV]},
	{tip:"在药品库中取出布氏漏斗",tag:[TAG_LIB,TAG_LIB_BUSHILOUDOU]},
	{tip:"打开减压抽滤装置",tag:TAG_CHOULV},
	{tip:"按下开关,启动机器",tag:[TAG_AIR_SIDE_NODE, TAG_AIR_SIDE_BT]},
	{tip:"将结晶后的2号烧杯溶液倒至布氏漏斗进行减压抽滤",tag:[TAG_BEAKER2],action:ACTION_DO1},
	{tip:"在药品库中取出蒸馏水",tag:[TAG_LIB,TAG_LIB_KETTLE],action:ACTION_DO3},
	{tip:"将烧杯润洗",tag:[TAG_KETTLE,TAG_KETTLE3]},
	{tip:"将润洗后的烧杯溶液继续倒至布氏漏斗进行减压抽滤",tag:[TAG_BEAKER2],action:ACTION_DO2},
	
	{tip:"在药品库中取出烧杯3号放在三角架上",tag:[TAG_LIB,TAG_LIB_BEAKER]},
	{tip:"药品库中取出蒸馏水",tag:[TAG_LIB,TAG_LIB_KETTLE]},
	{tip:"向3号烧杯加入蒸馏水",tag:[TAG_KETTLE,TAG_KETTLE4]},
	{tip:"药品库中取出表面皿1号，盖在3号烧杯上",tag:[TAG_LIB,TAG_LIB_BIAOMIANMIN],action:ACTION_DO1},
	{tip:"在药品库中取出酒精灯和火柴",tag:[TAG_LIB,TAG_LIB_JIUJINGDENG2]},
	{tip:"打开酒精灯灯帽",tag:[TAG_LAMP,TAG_DENGMAO],action:ACTION_DO1},
	{tip:"用火柴点燃酒精灯",tag:[TAG_LAMP,TAG_HUOCHAI]},
	{tip:"将酒精灯移至三脚架下",tag:[TAG_LAMP,TAG_JIUJINGDENG],action:ACTION_DO3},

	{tip:"取出布氏漏斗,晶体转移至表面皿上",tag:TAG_BUSHILOUDOU,action:ACTION_DO1},
	{tip:"在药品库中取出药匙,使之完全转移",tag:[TAG_LIB,TAG_LIB_GANGSHAO]},
	{tip:"等待干燥"},
	
	{tip:"将酒精灯移出三脚架",tag:[TAG_LAMP,TAG_JIUJINGDENG],action:ACTION_DO4},
	{tip:"灯帽熄灭",tag:[TAG_LAMP,TAG_DENGMAO],action:ACTION_DO2},
	{tip:"拿起灯帽，重新盖一次",tag:[TAG_LAMP,TAG_DENGMAO],action:ACTION_DO4},
	
	{tip:"在药品库中取出托盘天平",tag:[TAG_LIB,TAG_LIB_TIANPING2]},
	{tip:"在药品库中取同质量表面皿2号，放置天平右托盘",tag:[TAG_LIB,TAG_LIB_BIAOMIANMIN]},
	{tip:"将表面皿1号移到天平左托盘",tag:TAG_BIAOMIANMIN,action:ACTION_DO1},
	{tip:"移动游码，调整至平衡",tag:[TAG_TIANPING2,TAG_YOUMA],action:ACTION_DO1},
	{tip:"读取数值,计算转化率",tag:[TAG_TIANPING2]},
	{tip:"点击右上角，关闭窗口",tag:[TAG_AIR_SIDE_NODE,TAG_KEDU_CLOSE]},
	{tip:"在药品库中取出广口瓶和药匙",tag:[TAG_LIB,TAG_LIB_GUANGKOUPING]},
	{tip:"打开瓶盖",tag:[TAG_GUANG_BOTTLE,TAG_GUANG_PINGSAI],action:ACTION_DO1},
	{tip:"将表面皿1号上的苯甲酸装入广口瓶",tag:TAG_BIAOMIANMIN,action:ACTION_DO2},
	{tip:"使用药匙，装入完全",tag:[TAG_GUANG_BOTTLE,TAG_GUANG_GANGSHAO]},
	{tip:"盖上瓶盖",tag:[TAG_GUANG_BOTTLE,TAG_GUANG_PINGSAI],action:ACTION_DO2},
	{tip:"为广口瓶贴上标签",tag:[TAG_GUANG_BOTTLE,TAG_GUANGKOUPING]},
	{tip:"恭喜过关",over:true}
];
over = {tip:"恭喜过关"};



